home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 1.iso
/
ARGONET
/
PD
/
MATHS
/
RLAB
/
RLAB125.ZIP
/
!RLaB
/
rlib
/
trace
< prev
next >
Wrap
Text File
|
1994-09-23
|
524b
|
27 lines
//-------------------------------------------------------------------//
// Syntax: trace ( A )
// Description:
// Compute the trace (the sum of the diagonal elements) for the input
// matrix. `trace(A)' is the same as `sum( diag( A ) )'.
//-------------------------------------------------------------------//
trace = function(m)
{
if(m.class != "num")
{
error("must provide NUMERICAL input to trace()");
}
tr = 0;
for(i in 1:min( [m.nr, m.nc] ))
{
tr = tr + m[i;i];
}
return tr;
};